home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / comm / tcp / Amster-source.lha / Amster_Install / Source / sound.c < prev    next >
C/C++ Source or Header  |  2001-03-11  |  2KB  |  101 lines

  1. /*
  2. ** Amster - Datatype sound player
  3. ** Copyright © 1999-2000 by Gürer Özen
  4. **
  5. ** This program is free software; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include "amster.h"
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/datatypes.h>
  24. #include <proto/dtclass.h>
  25. #include <clib/datatypes_protos.h>
  26. #include <clib/alib_protos.h>
  27. #include <datatypes/datatypes.h>
  28. #include <datatypes/datatypesclass.h>
  29. #include <datatypes/soundclass.h>
  30.  
  31. #include "thread.h"
  32.  
  33. THREAD_DECL(snd_player);
  34.  
  35.  
  36. void snd_play(char *fname)
  37. {
  38.     if (!fname) return;
  39.     th_spawn(NULL, "Amster sound player", &snd_player, 0, fname);
  40. }
  41.  
  42.  
  43. THREAD(snd_player)
  44. {
  45.     thread t;
  46.     struct Library *DosBase;
  47.     struct Library *DataTypesBase;
  48.     Object *sample;
  49.     struct dtTrigger trigger;
  50.     long ssig, tsig;
  51.  
  52.     t = thr_init();
  53.     if (!t) return;
  54.     tsig = (1L << (t->port->mp_SigBit));
  55.  
  56.     DosBase = OpenLibrary("dos.library", 36);
  57.     if (!DosBase) {
  58.         thr_exit(t, 1);
  59.         return;
  60.     }
  61.     DataTypesBase = OpenLibrary("datatypes.library", 39);
  62.     if (!DataTypesBase) {
  63.         CloseLibrary(DosBase);
  64.         thr_exit(t, 1);
  65.         return;
  66.     }
  67.  
  68.     ssig = AllocSignal(-1);
  69.     if (ssig == -1) {
  70.         CloseLibrary(DataTypesBase);
  71.         CloseLibrary(DosBase);
  72.         thr_exit(t, 1);
  73.         return;
  74.     }
  75.  
  76.     sample = NewDTObject((char*)t->data, DTA_GroupID, GID_SOUND, TAG_DONE);
  77.     if (!sample) {
  78.         FreeSignal(ssig);
  79.         CloseLibrary(DataTypesBase);
  80.         CloseLibrary(DosBase);
  81.         thr_exit(t, 2);
  82.         return;
  83.     }
  84.  
  85.     SetDTAttrs(sample,NULL,NULL,SDTA_SignalBit,(1L << ssig),SDTA_SignalTask,t->task,TAG_DONE);
  86.  
  87.     trigger.MethodID = DTM_TRIGGER;
  88.     trigger.dtt_GInfo = NULL;
  89.     trigger.dtt_Function = STM_PLAY;
  90.     trigger.dtt_Data = NULL;
  91.     DoDTMethodA(sample, 0L, 0L, (Msg)&trigger);
  92.  
  93.     Wait((1L<<ssig)|tsig|SIGBREAKF_CTRL_C);
  94.  
  95.     DisposeDTObject(sample);
  96.     FreeSignal(ssig);
  97.     CloseLibrary(DataTypesBase);
  98.     CloseLibrary(DosBase);
  99.     thr_exit(t, 0);
  100. }
  101.